def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n ** 0.5) + 1):
        if n % i == 0:
            return False
    return True

def find_largest_prime(number):
    if len(number) != 4:
        return 0

    max_prime = 0
    for i in range(len(number)):
        for j in range(i, len(number)):
            current = int("".join(number[i:j+1]))
            if is_prime(current) and current > max_prime:
                max_prime = current

    return max_prime

num = input().strip()
result = find_largest_prime(num)
print(result)
